package com.shrct.businessprocess.project.impl;

import com.shrct.businessprocess.project.RCSalesAssignment;
import com.shrct.businessprocess.project.RCSalesAssignmentDAO;
import com.shrct.businessprocess.project.events.RCSalesAssignmentEventsManager;
import com.shrct.businessprocess.project.impl.RCSalesAssignmentImpl;
import edu.fudan.mylang.pf.BaseDAOService;
import edu.fudan.mylang.pf.IGenericQuery;
import java.util.Collection;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.project.RCSalesAssignmentDAO")
public class RCSalesAssignmentDAOImpl extends BaseDAOService<RCSalesAssignment> implements RCSalesAssignmentDAO {
  @Autowired
  private RCSalesAssignmentEventsManager eventsManager;
  
  public RCSalesAssignment create(final Procedure1<? super RCSalesAssignment> init) {RCSalesAssignment rCSalesAssignment=RCSalesAssignmentImpl.create(getObjectFactory());
    final Procedure1<RCSalesAssignment> _function = new Procedure1<RCSalesAssignment>() {
        public void apply(final RCSalesAssignment it) {
          init.apply(it);
          it.checkValid();
          it.start();
          RCSalesAssignmentDAOImpl.this.eventsManager.fireCreated(it);
        }
      };
    RCSalesAssignment _doubleArrow = ObjectExtensions.<RCSalesAssignment>operator_doubleArrow(rCSalesAssignment, _function);
    return _doubleArrow;
  }
  
  public void delete(final RCSalesAssignment value) {getObjectFactory().delete(value);
    
    this.eventsManager.fireDeleted(value);
  }
  
  public Collection<RCSalesAssignment> allSalesAssignments() {IGenericQuery<RCSalesAssignment> query=getObjectFactory().createGenericQuery(RCSalesAssignment.class,"select e from com.shrct.businessprocess.project.impl.RCSalesAssignmentImpl as e   where  e.active = 1  order by e.saler.name ASC    ");
    Collection<RCSalesAssignment> _list = query.list();
    return _list;
  }
}
